; tfree3.g
; called when tool 3 is freed

if heat.heaters[4].current > heat.coldExtrudeTemperature
    G1 E{-(global.DirectDriveExtruder =0 ? global.changeToolsRetracrion : global.changeToolsRetracrionDDE)} F{global.retractSpeedSlow*60}

M98 P"0:/sys/babystep/save.g" A1                                     ; 卸头时保存微步到config-override.g

var gridCompensationOn =0
if move.compensation.file != null
    set var.gridCompensationOn =1
    G29 S2

;Drop the bed
if !move.axes[2].homed
    M564 H0
;G91
;G1 Z4 F1000
;G90
if !move.axes[2].homed
    M564 H1

;Purge nozzle
;M98 P"purge.g"

;Move to Y safe position
if move.axes[1].userPosition>175 && move.axes[0].userPosition<150
    G53 G1 Y150 F50000
    M400

;Move In
G53 G1 X{global.T3parkX} Y150 F50000
G53 G1 X{global.T3parkX} Y200 F50000
G53 G1 X{global.T3parkX} Y220 F50000
G53 G1 X{global.T3parkX} Y{global.T3parkY + 0.5} F5000

;Open Coupler
if move.axes[3].homed
    M98 P"0:/macros/Coupler - Unlock"
else
    G91                                                              ; 使用相对坐标
    M400                                                             ; 变更电机电流前先确保之前的电机运动已经完成
    M913 C{global.cStallCurrent}                                     ; 设置挂头电机失速检测电流
    G1 H2 C-500 F5000                                                ; 挂头电机归位
    G92 C-45                                                         ; 设置挂头电机坐标
    G90                                                              ; 使用绝对坐标
    M913 C100                                                        ; 恢复电机电流到100%
    M98 P"0:/macros/Coupler - Unlock"                                ; 打开挂头锁
M400

;fan off
M106 P8 S0

;Move Out
G53 G1 X{global.T3parkX} Y175 F50000
if var.gridCompensationOn =1
    G29 S1
